<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class CategoryController extends Controller
{
    
    //艺术摄影
    public function art(Request $request)
    {
        $id = $_GET['id'];

    	$data = DB::table('image') -> where('state','1') -> where('categoryid',$id) -> orderBy('id','desc') -> paginate(6);
    	return view('home.art',['data' => $data,'request' => $request -> all()]);
    }

    public function order(Request $request)
    {
        $id = $_GET['id'];
        $order = $_GET['data'];
        if($order == 'time')
        {
            $order = 'imagedate';
        }
        $sort = $_GET['sort'];
        if($sort == '1')
        {
            $sort = 'asc';
        }elseif($sort == '2'){
            $sort = 'desc';
        }
        $date = DB::table('image') -> where('state','1') -> where('categoryid',$id) -> orderBy($order,$sort)  -> paginate(6);
        $str = '';
        foreach($date as $val){
            $imageURL = $val -> imageURL;
            $id = $val -> id;
            $str .='<li><a href="home/detail/'.$id.'"><img src="img/'.$imageURL.'" alt="img01"/></a></li>
                    ';

        }
        $data = array();
        $data['1'] = $str;
        $data['2'] = $request -> all();
        $data['3'] = $date;
        
        return response() -> json($data);
    }





}
